
####################
##钢之术士工具条————矩形柱参数建模类
##23-4-12
###################

#!/usr/bin/ruby
#$LOAD_PATH << '.'
#require "moduleRF"

module RF                                              #钢筋模块
       
    def RF.straight(length,dim,trRota,trtf,group)      #直线筋（长度，直径，旋转，移动，根群组）
        
        group2 = group.entities.add_group
        entities = group2.entities

        points = [
            Geom::Point3d.new(0,   0,   0),
            Geom::Point3d.new(length, 0,   0)
        ]
        edges = entities.add_line points[0],points[1]

        vector = Geom::Vector3d.new 1,0,0
        vector2 = vector.normalize!
        face = entities.add_face(entities.add_circle points[1], vector2, dim/2)
        face.followme(edges.all_connected)
        entities.transform_entities(trRota, group2)
        entities.transform_entities(trtf, group2)

        return group2 

    end

    def RF.oneElbow(length,elbowLength1,dim,group)     #一弯头筋（长度，弯头1，直径，根群组）<-（一次旋转，二次旋转）
        
        group2 = group.entities.add_group
        entities = group2.entities
        
        points = [
            Geom::Point3d.new(0,  dim/2, 0),
            Geom::Point3d.new(length-dim*3, dim/2,  0),
            Geom::Point3d.new(length-dim/2, dim*3,   0),
            Geom::Point3d.new(length-dim/2, elbowLength1,   0)
        ]
        edges = entities.add_line points[0],points[1]
        edges = entities.add_line points[2],points[3]

        cpoint = Geom::Point3d.new(length-dim*3, dim*3,   0)
        vector = Geom::Vector3d.new 0,0,1
        vector2 = Geom::Vector3d.new 1,0,0
        vector3 = vector.normalize!
        entities.add_arc cpoint, vector2, vector3, 2.5*dim, 270.degrees, 360.degrees
        
        vector = Geom::Vector3d.new 1,0,0
        vector2 = vector.normalize!
        face = entities.add_face(entities.add_circle points[0], vector2, dim/2)
        face.followme(edges.all_connected)
        return group2
       
    end

    def RF.stirrup(b,h,dia,trRota,trtf,group)          #方箍筋（b长度，h长度，直径，旋转，移动，根群组）

        group2 = group.entities.add_group
        entities = group2.entities

        o1x = dia/2+2.5*dia                 #o1-4是方箍的4个打弯圆心点
        o1y = dia/2+2.5*dia
        o3x = b-dia/2-2.5*dia               #o1-4是方箍的4个打弯圆心点
        o3y = h-dia/2-2.5*dia

        points = [                                  #8个角点
          Geom::Point3d.new(o1x,  o1y-2.5*dia,   0),
          Geom::Point3d.new(o1x-2.5*dia,  o1y,   0),
          Geom::Point3d.new(o1x-2.5*dia,  o3y,   0),
          Geom::Point3d.new(o1x,  o3y+2.5*dia,   0),
          Geom::Point3d.new(o3x,  o3y+2.5*dia,   0),
          Geom::Point3d.new(o3x+2.5*dia,  o3y,   0),
          Geom::Point3d.new(o3x+2.5*dia,  o1y,   0),
          Geom::Point3d.new(o3x,  o1y-2.5*dia,   0),
          Geom::Point3d.new(o1x,  o1y-2.5*dia,   dia)
        ]
        sin45 = 0.707
        tth1X = o1x+2.5*dia*sin45
        tth1y = o1y-2.5*dia*sin45
        tth2X = tth1X+10*sin45*dia
        tth2y = tth1y+10*sin45*dia
        edges = entities.add_line Geom::Point3d.new(tth1X,tth1y,0),Geom::Point3d.new(tth2X,tth2y,0)

        vector = Geom::Vector3d.new 1,1,0
        vector2 = vector.normalize!
        face = entities.add_face(entities.add_circle Geom::Point3d.new(tth2X,tth2y,0), vector2, dia/2)

        tth3X = o1x-2.5*dia*sin45
        tth3y = o1y+2.5*dia*sin45
        tth4X = tth3X+10*sin45*dia
        tth4y = tth3y+10*sin45*dia
        entities.add_line Geom::Point3d.new(tth3X,tth3y,dia),Geom::Point3d.new(tth4X,tth4y,dia)
        entities.add_line points[1],points[2]
        entities.add_line points[3],points[4]
        entities.add_line points[5],points[6]
        entities.add_line points[7],points[8]

        vector = Geom::Vector3d.new 0,0,1
        vector2 = Geom::Vector3d.new 1,0,0
        vector3 = vector.normalize!
        cpoint1 =   Geom::Point3d.new(o1x,  o1y,   0)
        cpoint2 =   Geom::Point3d.new(o1x,  o3y,   0)
        cpoint3 =   Geom::Point3d.new(o3x,  o3y,   0)
        cpoint4 =   Geom::Point3d.new(o3x,  o1y,   0)
        cpoint5 =   Geom::Point3d.new(o1x,  o1y,   dia)
        entities.add_arc cpoint1, vector2, vector3, 2.5*dia, 180.degrees, 315.degrees
        entities.add_arc cpoint2, vector2, vector3, 2.5*dia, 180.degrees, 90.degrees
        entities.add_arc cpoint3, vector2, vector3, 2.5*dia, 0.degrees, 90.degrees
        entities.add_arc cpoint4, vector2, vector3, 2.5*dia, 270.degrees, 360.degrees
        entities.add_arc cpoint5, vector2, vector3, 2.5*dia, 135.degrees, 270.degrees
        #entities.add_line points[5,6]
        #entities.add_line points[7,0]
        entities.transform_entities(trRota, group2)
        entities.transform_entities(trtf, group2)

        face.followme(edges.all_connected)

        return group2

    end

    def RF.hook(l,dia,trRota,trtf,group)               #拉钩筋（长度，直径，旋转，移动，根群组）
       
        group2 = group.entities.add_group
        entities = group2.entities

        points = [                                  #2个角点
          Geom::Point3d.new(3*dia,  0.5*dia,   0),
          Geom::Point3d.new(l-3*dia,  0.5*dia,   0)          
        ]
        entities.add_line points

        sin45 = 0.707
        tth1X = 3*dia-2.5*dia*sin45
        tth1y = 3*dia + 2.5*dia*sin45
        tth2X = tth1X+10*sin45*dia
        tth2y = tth1y+10*sin45*dia
        edges = entities.add_line Geom::Point3d.new(tth1X,tth1y,0),Geom::Point3d.new(tth2X,tth2y,0)

        vector = Geom::Vector3d.new 1,1,0
        vector2 = vector.normalize!
        face = entities.add_face(entities.add_circle Geom::Point3d.new(tth2X,tth2y,0), vector2, dia/2)

        tth3X = l - tth1X
        tth3y = tth1y
        tth4X = tth3X-10*sin45*dia
        tth4y = tth3y+10*sin45*dia
        entities.add_line Geom::Point3d.new(tth3X,tth3y,0),Geom::Point3d.new(tth4X,tth4y,0)
    
        vector = Geom::Vector3d.new 0,0,1
        vector2 = Geom::Vector3d.new 1,0,0
        vector3 = vector.normalize!
        cpoint1 =   Geom::Point3d.new(3*dia,  3*dia,   0)
        cpoint2 =   Geom::Point3d.new(l - 3*dia,  3*dia,   0)
        
        entities.add_arc cpoint1, vector2, vector3, 2.5*dia, 135.degrees, 270.degrees
        entities.add_arc cpoint2, vector2, vector3, 2.5*dia, 270.degrees, 405.degrees
        
        entities.transform_entities(trRota, group2)
        entities.transform_entities(trtf, group2)

        face.followme(edges.all_connected)

        return group2
      
    end
end

module Graph                                           #画图模块

    def Graph.rect(b,h,layer,group)                    #画矩形
        
        group2 = group.entities.add_group
        entities2 = group2.entities
             
        points = [
           Geom::Point3d.new(layer, layer, 0),
           Geom::Point3d.new(b-layer, layer, 0),
           Geom::Point3d.new(b-layer, h-layer, 0),
           Geom::Point3d.new(layer, h-layer, 0),
           Geom::Point3d.new(layer, layer, 0)
       ]

       entities2.add_line points
       return group2 
    end

    def Graph.circle(point,vector,r,isFace,group)      #画圆形

        group2 = group.entities.add_group
        entities2 = group2.entities
        
        edges = entities2.add_circle( point, vector, r)
        if isFace  
            entities2.add_face(edges) 
        end

        point2 = point + [r,0,0]
        entities2.add_line( point, point2)

    end

    def Graph.line(point1,point2,group)                #画直线
        #add_line
        group2 = group.entities.add_group
        entities2 = group2.entities

        entities2.add_line(point1,point2)
        return group2 

    end

    def Graph.text(point,text,group)                   #画文字
        #add_text
        group2 = group.entities.add_group
        entities2 = group2.entities

        entities2.add_text(text,point)
        return group2


    end


end

class Pillar                                           #柱类（矩形柱）

    include RF
    include Graph

    
    def initialize(bl,hl,layer,strpDim,angRFDim,angRFNum,ishOrL,     #构造函数
                    b_RFDim,b_RFNum,h_RFDim,h_RFNum,
                    h_JointLength,l_JointLength,
                    elbowRFAncLength,strpRFAncLength,
                    b_stirrupLeg,h_stirrupLeg,
                    axis_X_pos,axis_Y_pos,
                    axis_X_text, axis_Y_text
                )
        
        @model = Sketchup.active_model
        @group = @model.active_entities.add_group
        
        @b_length, @h_length = bl.to_f.mm, hl.to_f.mm     #b边长度、h边长度
        @layer = layer.to_f.mm                            #保护层
        @stirrupDim = strpDim.to_f.mm                      #箍筋直径
        @angRFDim = angRFDim.to_f.mm                       #角筋直径
        @angRFNum = angRFNum.to_i                         #角筋数量
        @b_RFDim = b_RFDim.to_f.mm                        #b边筋直径
        @b_RFNum = b_RFNum.to_i                           #b边筋数量
        @h_RFDim = h_RFDim.to_f.mm                        #h边筋直径
        @h_RFNum = h_RFNum.to_i                          #h边筋数量
        @ishOrL = ishOrL                                 #是否高低桩
        @mainRFnum = @angRFNum+@b_RFNum*2+@h_RFNum*2            #主筋总数

        @h_JointLength = h_JointLength.to_f.mm              #高桩伸出长度
        @l_JointLength = l_JointLength.to_f.mm              #低桩伸出长度
        @elbowRFAncLength = elbowRFAncLength.to_f.mm        #弯锚筋锚入直段长度
        @strpRFAncLength = strpRFAncLength.to_f.mm          #直锚筋锚入长度
        @b_stirrupLeg = b_stirrupLeg.to_i                      #b边箍筋肢数
        @h_stirrupLeg = h_stirrupLeg.to_i                       #h边箍筋肢数

        #构件基点为柱截面左下角端点。轴线定义交点与基点相对坐标和四个方向端点坐标。并在上右两处设置轴号标记。
        @axis_X_pos, @axis_Y_pos = axis_X_pos.to_f.mm, axis_Y_pos.to_f.mm        #坐标
        @defLength = 1500.to_f.mm                                               #线长
        @axis_X_text, @axis_Y_text = axis_X_text, axis_Y_text                   #轴号

        
        def hlTorF(i,bn,hn,is)                         #高低桩判断

            re = true
                #puts i,bn,hn,is
            if !is
                re = !re 
            end

            case i
            when 0
    
            when 1
                if bn % 2 == 0
                    re = !re 
                end
                #puts bn
                #puts re
            when 2
                if (bn + hn) % 2 != 0
                    re = !re 
                end
            when 3
                if hn % 2 == 0
                    re = !re 
                end
            end
            re

        end
        @angRFhlTorF = [true,true,true,true]
        (0..3).each do |i|  
            @angRFhlTorF[i] = hlTorF(i,@b_RFNum,@h_RFNum,@ishOrL)
        end





    end

    def drawRectBorder                                   #绘制柱边框
        
        Graph.rect(@b_length,@h_length,0,@group)
        
    end

    def drawRectLayer                                    #绘制箍边框
                             
        Graph.rect(@b_length,@h_length,@layer,@group)
        
    end

    def drawRectStrpDn                                   #绘制箍净框
           
        Graph.rect(@b_length,@h_length,@layer+@stirrupDim,@group)
        
    end

    def drawAngRFPos                                     #绘制角筋定位
    
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 
        
        points = [
            Geom::Point3d.new(arcRFpos, arcRFpos, 0),
            Geom::Point3d.new(@b_length-arcRFpos, arcRFpos, 0),
            Geom::Point3d.new(@b_length-arcRFpos, @h_length-arcRFpos, 0),
            Geom::Point3d.new(arcRFpos, @h_length-arcRFpos, 0)
        ]

        vector = Geom::Vector3d.new 0,0,1
       
        (0..3).each do |i|  
            Graph.circle(points[i],vector,@angRFDim/2,@angRFhlTorF[i],@group)
        end
    
        
    end

    def drawBorderRFPos                                  #绘制边筋定位
    
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 

        b_mainRFInterval = (@b_length - arcRFpos*2)/(@b_RFNum+1)    #边筋间距计算
        h_mainRFInterval = (@h_length - arcRFpos*2)/(@h_RFNum+1) 

        vector = Geom::Vector3d.new 0,0,1

        (0..@b_RFNum-1).each do |i|                 #绘制b边筋

            point = Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), @h_length-arcRFpos, 0)
            
            if i%2 == 0
                Graph.circle(point,vector,@angRFDim/2,!@angRFhlTorF[3],@group)
            else
                Graph.circle(point,vector,@angRFDim/2,@angRFhlTorF[3],@group)
            end

            point = Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), arcRFpos, 0)
            if i%2 == 0
                Graph.circle(point,vector,@angRFDim/2,!@angRFhlTorF[0],@group)
            else
                Graph.circle(point,vector,@angRFDim/2,@angRFhlTorF[0],@group)
            end
            
        end
        
        (0..@h_RFNum-1).each do |i|                 #绘制h边筋
            
            point = Geom::Point3d.new(arcRFpos, arcRFpos+h_mainRFInterval*(i+1), 0)
            if i%2 == 0
                Graph.circle(point,vector,@angRFDim/2,!@angRFhlTorF[0],@group)
            else
                Graph.circle(point,vector,@angRFDim/2,@angRFhlTorF[0],@group)
            end

            point = Geom::Point3d.new(@b_length-arcRFpos, arcRFpos+h_mainRFInterval*(i+1), 0)
            if i%2 == 0
                Graph.circle(point,vector,@angRFDim/2,!@angRFhlTorF[1],@group)
            else
                Graph.circle(point,vector,@angRFDim/2,@angRFhlTorF[1],@group)
            end
            
        end

        
        
    
        
    end

    def drawStirrRFPos                                  #绘制箍筋定位
    
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 
    
        b_neiIntervalNum = @b_RFNum+1                   #b边主筋间数
        h_neiIntervalNum = @h_RFNum+1                   #h边主筋间数
    
        b_mainRFInterval = (@b_length - arcRFpos*2)/b_neiIntervalNum   #边筋间距计算
        h_mainRFInterval = (@h_length - arcRFpos*2)/h_neiIntervalNum
    
        b_neiLegNum = @b_stirrupLeg - 2                 #b边箍筋内肢数
        h_neiLegNum = @h_stirrupLeg - 2                 #h边箍筋内肢数                        
    
    
        if b_neiIntervalNum <= b_neiLegNum              #如果内间数小于等于内肢数，设内肢数等于内间数-1      
            b_neiLegNum = b_neiIntervalNum - 1
        end
    
        if h_neiIntervalNum <= h_neiLegNum              #如果内间数小于等于内肢数，设内肢数等于内间数-1      
            h_neiLegNum = h_neiIntervalNum - 1
        end
    
        def getLegItvalRFNum (itvalNum,legNum)          #根据剩余的主筋间数和箍筋肢数，计算箍套间数。
            return ((itvalNum+2)/(legNum+1.1)).floor
        end
    
    
        entities = Sketchup.active_model.entities
    
        ################b边箍定位#################
    
        countLegItvalRFNum = 0  #累计已布肢钢筋间数 
        countNeiLegNum = 0      #累计已布内肢数
        legItvalRFNum = getLegItvalRFNum(b_neiIntervalNum,b_neiLegNum)   #当前肢间钢筋间数，下取整
        while countNeiLegNum < b_neiLegNum    #如果内肢数小于累计已布内肢数
        
            if b_neiLegNum - countNeiLegNum == 1
    
                b_stirrRFPos = Graph.rect(@stirrupDim *2 + @angRFDim,@h_length - @layer*2 ,0,@group)
                if legItvalRFNum + countLegItvalRFNum > @b_RFNum
                    legItvalRFNum = legItvalRFNum - 1
                end
                entities.transform_entities(Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,0]), b_stirrRFPos)
                
                break
            end
            
            
            b_stirrRFPos = Graph.rect(b_mainRFInterval * legItvalRFNum + @stirrupDim *2 + @angRFDim,@h_length - @layer*2 ,0,@group)
            if legItvalRFNum*2 + countLegItvalRFNum > @b_RFNum
                legItvalRFNum = legItvalRFNum - 1
            end
            entities.transform_entities(Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,0]), b_stirrRFPos)
    
            countLegItvalRFNum += legItvalRFNum *2   #累计肢间钢筋间数 += 肢间钢筋间数 * 2
            countNeiLegNum  += 2                #累计已布内肢数 += 2
            legItvalRFNum = getLegItvalRFNum(b_neiIntervalNum - countLegItvalRFNum,b_neiLegNum - countNeiLegNum)
        
        
        end
        
        ################h边箍定位#################
    
        countLegItvalRFNum = 0  #累计已布肢钢筋间数 
        countNeiLegNum = 0      #累计已布内肢数
        legItvalRFNum = getLegItvalRFNum(h_neiIntervalNum,h_neiLegNum)   #当前肢间钢筋间数，下取整
        while countNeiLegNum < h_neiLegNum    #如果内肢数小于累计已布内肢数
        
            if h_neiLegNum - countNeiLegNum == 1
    
                h_stirrRFPos = Graph.rect(@b_length - @layer*2 ,@stirrupDim *2 + @angRFDim,0,@group)
                if legItvalRFNum + countLegItvalRFNum > @h_RFNum
                    legItvalRFNum = legItvalRFNum - 1
                end
                entities.transform_entities(Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,0]), h_stirrRFPos)
                
                break
            end
            
            
            h_stirrRFPos = Graph.rect(@b_length - @layer*2 ,h_mainRFInterval * legItvalRFNum + @stirrupDim *2 + @angRFDim,0,@group)
            if legItvalRFNum*2 + countLegItvalRFNum > @h_RFNum
                legItvalRFNum = legItvalRFNum - 1
            end
            entities.transform_entities(Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,0]), h_stirrRFPos)
    
            countLegItvalRFNum += legItvalRFNum *2   #累计肢间钢筋间数 += 肢间钢筋间数 * 2
            countNeiLegNum  += 2                #累计已布内肢数 += 2
            legItvalRFNum = getLegItvalRFNum(h_neiIntervalNum - countLegItvalRFNum,h_neiLegNum - countNeiLegNum)
        
        
        end    
        
    
    
    
    end

    def drawAxis                                        #绘制轴线
        
        point1 = Geom::Point3d.new(@axis_X_pos, @axis_Y_pos, 0)
        point2 = Geom::Point3d.new(@axis_X_pos+@defLength, @axis_Y_pos, 0)
        point3 = Geom::Point3d.new(@axis_X_pos-@defLength, @axis_Y_pos, 0)
        point4 = Geom::Point3d.new(@axis_X_pos, @axis_Y_pos+@defLength, 0)
        point5 = Geom::Point3d.new(@axis_X_pos, @axis_Y_pos-@defLength, 0)

        group2 = @group.entities.add_group
        entities2 = group2.entities
        
        Graph.line(point1,point2,group2) 
        Graph.line(point1,point3,group2) 
        Graph.line(point1,point4,group2) 
        Graph.line(point1,point5,group2) 

        point2 = point2+[100.to_f.mm,0,0]
        point4 = point4+[0,100.to_f.mm,0]
       
        Graph.text(point2,@axis_X_text,group2)
        Graph.text(point4,@axis_Y_text,group2)

        vector = Geom::Vector3d.new 0,0,1
        entities2.add_circle( point2, vector, 100.to_f.mm)
        entities2.add_circle( point4, vector, 100.to_f.mm)

    end

    def drawAngRF                                        #绘制角筋
    
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 

        entities = Sketchup.active_model.entities

        trRotaY90 = Geom::Transformation.rotation [0, 0, 0], [0, 1, 0], 90.degrees   #沿Y轴顺时针转90度参数
        trRotaZ90 = Geom::Transformation.rotation [0, 0, 0], [0, 0, 1], 90.degrees   #沿Z轴顺时针转90度参数
        trRotaZ270 = Geom::Transformation.rotation [0, 0, 0], [0, 0, 1], -90.degrees   #沿Z轴逆时针转90度参数

        trtfpoint = [
            Geom::Transformation.new([arcRFpos+@angRFDim/2, arcRFpos, @h_JointLength]),
            Geom::Transformation.new([@b_length-arcRFpos-@angRFDim/2, arcRFpos, @h_JointLength]),
            Geom::Transformation.new([@b_length-arcRFpos-@angRFDim/2, @h_length-arcRFpos, @h_JointLength]),
            Geom::Transformation.new([arcRFpos+@angRFDim/2, @h_length-arcRFpos, @h_JointLength])
        ]
        trtfpoint = [
            [arcRFpos+@angRFDim/2, arcRFpos, @h_JointLength],
            [@b_length-arcRFpos-@angRFDim/2, arcRFpos, @h_JointLength],
            [@b_length-arcRFpos-@angRFDim/2, @h_length-arcRFpos, @h_JointLength],
            [arcRFpos+@angRFDim/2, @h_length-arcRFpos, @h_JointLength]
        ]
       
        (0..3).each do |i|  
            
            
            if @angRFhlTorF[i]
                elbowRF = RF.oneElbow(@h_JointLength + @elbowRFAncLength,@angRFDim*6,@angRFDim,@group)
            else
                elbowRF = RF.oneElbow(@l_JointLength + @elbowRFAncLength,@angRFDim*6,@angRFDim,@group)
                
                trtfpoint[i][2] = @l_JointLength
            end

            
            entities.transform_entities(trRotaY90, elbowRF)
            
            if i==1 || i==2
                entities.transform_entities(trRotaZ270, elbowRF)
            else
                entities.transform_entities(trRotaZ90, elbowRF)
            end
            entities.transform_entities(Geom::Transformation.new(trtfpoint[i]), elbowRF)
        end
    
        
    end

    def drawBorderRF                                     #绘制边筋
    
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 

        b_mainRFInterval = (@b_length - arcRFpos*2)/(@b_RFNum+1)    #边筋间距计算
        h_mainRFInterval = (@h_length - arcRFpos*2)/(@h_RFNum+1) 

        trRota = Geom::Transformation.rotation [0, 0, 0], [0, 1, 0], 90.degrees   #沿Y轴顺时针转90度参数

        (0..@b_RFNum-1).each do |i|                 #绘制b边筋

            if i%2 == 0 && !@angRFhlTorF[3] || i%2 != 0 && @angRFhlTorF[3]

                RF.straight(@h_JointLength + @strpRFAncLength,@b_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), @h_length-arcRFpos, @h_JointLength)),@group)         
            else
                RF.straight(@l_JointLength + @strpRFAncLength,@b_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), @h_length-arcRFpos, @l_JointLength)),@group)
            end



            point = Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), arcRFpos, 0)
            if i%2 == 0 && !@angRFhlTorF[0] || i%2 != 0 && @angRFhlTorF[0]
                RF.straight(@h_JointLength + @strpRFAncLength,@b_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), arcRFpos, @h_JointLength)),@group)
            else
                RF.straight(@l_JointLength + @strpRFAncLength,@b_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos+b_mainRFInterval*(i+1), arcRFpos, @l_JointLength)),@group)
            end
            
        end
        
        (0..@h_RFNum-1).each do |i|                 #绘制h边筋
            

            if i%2 == 0 && !@angRFhlTorF[0] || i%2 != 0 && @angRFhlTorF[0]
                RF.straight(@h_JointLength + @strpRFAncLength,@h_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos,arcRFpos+h_mainRFInterval*(i+1),  @h_JointLength)),@group)
               
            else
                RF.straight(@l_JointLength + @strpRFAncLength,@h_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(arcRFpos,arcRFpos+h_mainRFInterval*(i+1),  @l_JointLength)),@group)
           
            end

            if i%2 == 0 && !@angRFhlTorF[1] || i%2 != 0 && @angRFhlTorF[1]
                RF.straight(@h_JointLength + @strpRFAncLength,@h_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(@b_length-arcRFpos,arcRFpos+h_mainRFInterval*(i+1),  @h_JointLength)),@group)
                
            else
                RF.straight(@l_JointLength + @strpRFAncLength,@h_RFDim,trRota,Geom::Transformation.new(Geom::Point3d.new(@b_length-arcRFpos,arcRFpos+h_mainRFInterval*(i+1),  @l_JointLength)),@group)
                
            end
            
        end
      
    
    
    
    end

    def drawWaiStirrRF                                 #绘制外箍筋
    
    
        RF.stirrup(@b_length-@layer*2,@h_length-@layer*2,@stirrupDim,
            Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
            Geom::Transformation.new([@layer,@layer,0]),
        @group)

        RF.stirrup(@b_length-@layer*2,@h_length-@layer*2,@stirrupDim,
            Geom::Transformation.rotation([@b_length/2-@layer, @h_length/2-@layer, 0], [0, 0, 1], 180.degrees),
            Geom::Transformation.new([@layer,@layer,-500.to_f.mm]),
        @group)
    
        RF.stirrup(@b_length-@layer*2,@h_length-@layer*2,@stirrupDim,
            Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
            Geom::Transformation.new([@layer,@layer,-1000.to_f.mm]),
        @group)

        RF.stirrup(@b_length-@layer*2,@h_length-@layer*2,@stirrupDim,
            Geom::Transformation.rotation([@b_length/2-@layer, @h_length/2-@layer, 0], [0, 0, 1], 180.degrees),
            Geom::Transformation.new([@layer,@layer,100.to_f.mm]),
        @group)

        RF.stirrup(@b_length-@layer*2,@h_length-@layer*2,@stirrupDim,
            Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
            Geom::Transformation.new([@layer,@layer,1000.to_f.mm]),
        @group)

   
    end 

    def drawNeiStirrRF                                 #绘制内箍筋
    
     
        arcRFpos = @layer + @stirrupDim + @angRFDim/2 

        b_neiIntervalNum = @b_RFNum+1                   #b边主筋间数
        h_neiIntervalNum = @h_RFNum+1                   #h边主筋间数

        b_mainRFInterval = (@b_length - arcRFpos*2)/b_neiIntervalNum   #边筋间距计算
        h_mainRFInterval = (@h_length - arcRFpos*2)/h_neiIntervalNum

        b_neiLegNum = @b_stirrupLeg - 2                 #b边箍筋内肢数
        h_neiLegNum = @h_stirrupLeg - 2                 #h边箍筋内肢数                        


        if b_neiIntervalNum <= b_neiLegNum              #如果内间数小于等于内肢数，设内肢数等于内间数-1      
            b_neiLegNum = b_neiIntervalNum - 1
        end

        if h_neiIntervalNum <= h_neiLegNum              #如果内间数小于等于内肢数，设内肢数等于内间数-1      
            h_neiLegNum = h_neiIntervalNum - 1
        end

        def getLegItvalRFNum (itvalNum,legNum)          #根据剩余的主筋间数和箍筋肢数，计算箍套间数。
            return ((itvalNum+2)/(legNum+1.1)).floor
        end


        entities = Sketchup.active_model.entities

        ################b边箍#################

        countLegItvalRFNum = 0  #累计已布肢钢筋间数 
        countNeiLegNum = 0      #累计已布内肢数
        legItvalRFNum = getLegItvalRFNum(b_neiIntervalNum,b_neiLegNum)   #当前肢间钢筋间数，下取整
        while countNeiLegNum < b_neiLegNum    #如果内肢数小于累计已布内肢数
        
            if b_neiLegNum - countNeiLegNum == 1

                #RF.hook(l,dia,trRota,trtf,group)
                #b_stirrRFPos = Graph.rect(@stirrupDim *2 + @angRFDim,@h_length - @layer*2 ,0,@group)

                if legItvalRFNum + countLegItvalRFNum > @b_RFNum
                    
                    legItvalRFNum = legItvalRFNum - 1

                end

                RF.hook(@h_length - @layer*2,@stirrupDim,
                        Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 90.degrees),
                        Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer + @b_RFDim + @stirrupDim*2 ,@layer,@stirrupDim]),
                    @group)
                RF.hook(@h_length - @layer*2,@stirrupDim,
                        Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 90.degrees),
                        Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer + @b_RFDim + @stirrupDim*2 ,@layer,@stirrupDim+1000.to_f.mm]),
                    @group)
                #entities.transform_entities(Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,0]), b_stirrRFPos)
                
                break
            end
            
            
            #b_stirrRFPos = Graph.rect(b_mainRFInterval * legItvalRFNum + @stirrupDim *2 + @angRFDim,@h_length - @layer*2 ,0,@group)
            
            
            rf1 = RF.stirrup(legItvalRFNum*b_mainRFInterval+@b_RFDim+@stirrupDim*2,@h_length-@layer*2,@stirrupDim,
                Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,@stirrupDim]),
            @group)
            rf2 = RF.stirrup(legItvalRFNum*b_mainRFInterval+@b_RFDim+@stirrupDim*2,@h_length-@layer*2,@stirrupDim,
                Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,@stirrupDim+1000.to_f.mm]),
            @group)


            if legItvalRFNum*2 + countLegItvalRFNum > @b_RFNum
                legItvalRFNum = legItvalRFNum - 1
                entities.transform_entities(Geom::Transformation.new([-b_mainRFInterval ,0,0]), rf1)
                entities.transform_entities(Geom::Transformation.new([-b_mainRFInterval ,0,0]), rf2)
            
            end



            #entities.transform_entities(Geom::Transformation.new([b_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@layer,0]), b_stirrRFPos)

            countLegItvalRFNum += legItvalRFNum *2   #累计肢间钢筋间数 += 肢间钢筋间数 * 2
            countNeiLegNum  += 2                #累计已布内肢数 += 2
            legItvalRFNum = getLegItvalRFNum(b_neiIntervalNum - countLegItvalRFNum,b_neiLegNum - countNeiLegNum)
        
        
        end
        
        ################h边箍#################

        countLegItvalRFNum = 0  #累计已布肢钢筋间数 
        countNeiLegNum = 0      #累计已布内肢数
        legItvalRFNum = getLegItvalRFNum(h_neiIntervalNum,h_neiLegNum)   #当前肢间钢筋间数，下取整
        while countNeiLegNum < h_neiLegNum    #如果内肢数小于累计已布内肢数
        
            if h_neiLegNum - countNeiLegNum == 1

                #h_stirrRFPos = Graph.rect(@b_length - @layer*2 ,@stirrupDim *2 + @angRFDim,0,@group)
                if legItvalRFNum + countLegItvalRFNum > @h_RFNum
                    legItvalRFNum = legItvalRFNum - 1
                end
                #entities.transform_entities(Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,0]), h_stirrRFPos)
                RF.hook(@b_length - @layer*2,@stirrupDim,
                    Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                    Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@stirrupDim*2]),
                @group)
                RF.hook(@b_length - @layer*2,@stirrupDim,
                    Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                    Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@stirrupDim*2+1000.to_f.mm]),
                @group)
                break
            end
            
            
            #h_stirrRFPos = Graph.rect(@b_length - @layer*2 ,h_mainRFInterval * legItvalRFNum + @stirrupDim *2 + @angRFDim,0,@group)
            
            
            #entities.transform_entities(Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,0]), h_stirrRFPos)
            rf1 = RF.stirrup(@b_length-@layer*2,legItvalRFNum*h_mainRFInterval+@h_RFDim+@stirrupDim*2,@stirrupDim,
                Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@stirrupDim*2]),
            @group)
            rf2 = RF.stirrup(@b_length-@layer*2,legItvalRFNum*h_mainRFInterval+@h_RFDim+@stirrupDim*2,@stirrupDim,
                Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], 0.degrees),
                Geom::Transformation.new([@layer,h_mainRFInterval * (legItvalRFNum + countLegItvalRFNum) + @layer,@stirrupDim*2+1000.to_f.mm]),
            @group)
            if legItvalRFNum*2 + countLegItvalRFNum > @h_RFNum
                legItvalRFNum = legItvalRFNum - 1

                entities.transform_entities(Geom::Transformation.new([0,-h_mainRFInterval,0]), rf1)
                entities.transform_entities(Geom::Transformation.new([0,-h_mainRFInterval,0]), rf2)
            end


            countLegItvalRFNum += legItvalRFNum *2   #累计肢间钢筋间数 += 肢间钢筋间数 * 2
            countNeiLegNum  += 2                #累计已布内肢数 += 2
            legItvalRFNum = getLegItvalRFNum(h_neiIntervalNum - countLegItvalRFNum,h_neiLegNum - countNeiLegNum)
               
        end    
   
    end

    def trtf(x,y,z)                           #移动到指定位置
        
        
        ent =  @group.entities
        
        ent.transform_entities(Geom::Transformation.new([x.to_f.mm,y.to_f.mm,z.to_f.mm]), @group)

    end


    def self.create_Pillar(params)

        puts params
        if params[6] == 'true'
            params[6] = true
        else
            params[6] = false
        end
        p = Pillar.new(params[0],params[1],params[2],params[3],params[4],params[5],
            params[6],params[7],params[8],params[9],params[10],params[11],params[12],
            params[13],params[14],params[15],params[16],params[17],params[18],params[19],params[20])
        

        
         p.drawRectBorder if params[21]
         p.drawRectLayer if params[22]
         p.drawRectStrpDn if params[23]
         p.drawAngRFPos if params[24]
         p.drawBorderRFPos if params[25]
         p.drawAngRF if params[26]
         p.drawBorderRF if params[27]
         p.drawStirrRFPos if params[28]
         p.drawWaiStirrRF if params[29]
         p.drawNeiStirrRF if params[30]
         p.drawAxis
  
        return p
    end

    def self.create_Dialog

        dialog = UI::HtmlDialog.new(
            {
              :dialog_title => "创建框架柱类",
              :preferences_key => "com.sample.plugin",
              :scrollable => true,
              :resizable => true,
              :width => 600,
              :height => 800,
              :left => 100,
              :top => 100,
              :min_width => 50,
              :min_height => 50,
              :max_width =>1000,
              :max_height => 1000,
              :style => UI::HtmlDialog::STYLE_DIALOG
            })
            dialog.set_file File.join(File.dirname(__FILE__), 'htmldialog/pillar.html')
            dialog.show
            dialog.add_action_callback("confirm") { |action, params|
                # params即js传过来的值
                create_Pillar(params)
            }

            dialog.add_action_callback("cancel"){
                dialog.close
            }


    end
end


time1 = Time.now.to_i 
  
(0..35).each do |i| 
p = Pillar.create_Pillar([750,700,25,10,25,4,true,25,6,25,6,2500,1500,1200,850,6,6,375,550,'E','5',true,true,true,true,true,true,true,true,true,true])
p.trtf(1000,1000,-4000)
p = Pillar.create_Pillar([750,700,25,10,25,4,true,25,6,25,6,2500,1500,1200,850,6,6,375,550,'E','6',true,true,true,true,true,true,true,true,true,true])
p.trtf(8200,1000,-4000)
p = Pillar.create_Pillar([750,700,25,10,25,4,true,25,6,25,6,2500,1500,1200,850,6,6,375,550,'E','7',true,true,true,true,true,true,true,true,true,true])
p.trtf(15400,1000,-4000)
end

time2 = Time.now.to_i 
sec = time2-time1
"%02d:%02d:%02d" % [sec / 3600, sec / 60 % 60, sec % 60]